set more 1

/*
File:	cepr_basic_hours.do
Date:	Nov 21, 2006
	Feb 15, 2008
	Feb 10, 2009
	Feb 22, 2011
	Jan 4, 2012
	Jan 7, 2013
	Dec 20, 2013
	Mar 12, 2015, CEPR ORG Version 2.0
	Apr  1, 2015, CEPR ORG Version 2.0.1
	March 1, 2016, CEPR ORG Version 2.1
	Oct 12, 2016, CEPR ORG Version 2.1.1
	Feb 9, 2017, CEPR ORG Version 2.2
	Apr 21, 2017, CEPR ORG Version 2.2.1
	Apr 10, 2018, CEPR ORG Version 2.3
	Mar 22, 2019, CEPR ORG Version 2.4
	Jul 24, 2019, CEPR ORG Version 2.4.1
	Feb 05, 2020, CEPR ORG Version 2.5
	
Desc:	Creates consistent hours variables for CEPR extract of Basic CPS
Note:	See copyright notice at end of program.
*/

/* note: any pre-1994 data processing is not yet correct;
         use only to process data from 1994 forward
*/

/* Determine data year */
local year=year in 1

/* collect NBER-style hours variables */

	/* actual hours last week */

gen hourslwa=.

if 1994<=`year' { /* NBER variable */
* not available
}
lab var hourslwa "Hours last week, all jobs"
notes hourslwa: Unedited
notes hourslwa: Available 1979-93 only
notes hourslwa: CPS: a-hrsl

gen hourslw=.

if `year'==1991 {
replace hourslw=adhrs1
}
if 1994<=`year' & `year'<=2020 {
replace hourslw=pehractt
replace hourslw=. if pehractt<0
}
lab var hourslw "Hours last week, all jobs"
notes hourslw: Actual hours worked on all jobs
notes hourslw: Edited
notes hourslw: CPS: a-hrsl, pehractt

gen hourslwm=.

if 1994<=`year' & `year'<=2020 {
replace hourslwm=pehract1
replace hourslwm=. if pehract1<0
}
lab var hourslwm "Hours last week, main job"
notes hourslwm: Actual hours worked on main job
notes hourslwm: Edited
notes hourslwm: CPS: pehract1
notes hourslwm: Available 94-on


	/* reason for part-time last week */
	
gen reason79=.
gen reason94=.

if 1979<=`year' & `year'<=1993 {
	
	if year==1991 {replace reason79=adftreas}
	if year~=1991 {replace reason79=reasonlw}

lab var reason79 "Why <35 hours last week"
#delimit ;
lab def reason79
1 "Slack work"
2 "Material shortage"
3 "Plant or machine repair"
4 "New job started during week"
5 "Job terminated during week"
6 "Could only find part-time work"
7 "Holiday"
8 "Labor dispute"
9 "Bad weather"
10 "Own illness"
11 "On vacation"
12 "Too busy with school, house"
13 "Did not want full-time work"
14 "Full-time work week is <35 hours"
15 "Other"
;
#delimit cr
lab val reason79 reason79
}
if 1994<=`year' & `year'<=2020 {

replace reason94=pehrrsn3
replace reason94=. if pehrrsn3<1
replace reason94=. if 13<pehrrsn3

#delimit ;
lab def reason94
1 "Slack work"
2 "Seasonal work"
3 "Job started or ended during week"
4 "On vacation"
5 "Own illness"
6 "Holiday"
7 "Child-care problems"
8 "Other family/personal obligations"
9 "Labor dispute" 
10 "Bad weather"
11 "School/training"
12 "Civic/military duty"
13 "Other"
;
#delimit cr
lab val reason94 reason94
}

lab var reason79 "Why <35 hours last week"
notes reason79: Available 1979-93 only
notes reason79: See also why3579
notes reason79: CPS: a-ftreas

lab var reason94 "Why <35 hours last week"
notes reason94: Available 1994- only
notes reason94: CPS: perhrrsn3

	/* why absent last week */

capture gen absent79=.
capture gen absent94=.

if 1979<=`year' & `year'<=1993 {

	if `year'==1991 {replace absent79=adwhyabs}
	if `year'~=1991 {replace absent79=absentlw}
}
#delimit ;
lab def absent79
1 "Own illness"
2 "On vacation"
3 "Bad weather"
4 "Labor dispute"
5 "New job to begin w/in 30 days"
6 "Temporary layoff (<30 days)"
7 "Indefinite layoff (30+ days)"
8 "Other"
;
#delimit cr
lab val absent79 absent79

if 1994<=`year' & `year'<=2020 {

replace absent94=peabsrsn
replace absent94=. if peabsrsn<1
replace absent94=. if 14<peabsrsn
}
#delimit ;
lab def absent94
1 "Layoff"
2 "Slack work/business conditions"
3 "Waiting for a new job to begin"
4 "On vacation"
5 "Own illness"
6 "Child-care problems"
7 "Other family/personal"
8 "Maternity/paternity"
9 "Labor dispute"
10 "Bad weather"
11 "School/training"
12 "Civic/military duty"
13 "Does not work"
14 "Other"
;
#delimit cr
lab val absent94 absent94

lab var absent79 "Why absent last week"
notes absent79: Available 1979-93 only
notes absent79: CPS: a-whyabs

lab var absent94 "Why absent last week"
notes absent94: Available 1994- only
notes absent94: CPS: peabsrsn

	/* being paid for time off last week */

capture gen abpaid=.

if 1994<=`year' & `year'<=2020 {
replace abpaid=peabspdo
replace abpaid=0 if peabspdo==2
replace abpaid=. if peabspdo==-1
}

lab var abpaid "Paid for time off last week"
notes abpaid: Availbe if 4<=absent94<=12 | absent94==14
notes abpaid: Available 1994- only
notes abpaid: CPS: peabspdo


	/* usual weekly hours */

capture gen uhours=.
capture gen uhourse=.
replace peernhro=. if peernhro<0

if `year'==1991 {
replace uhourse=aduslhrs
replace uhourse=. if aduslhrs<0 | 100<=aduslhrs
}
if 1994<=`year' & `year'<=2020 {
replace uhourse=pehrusl1
replace uhourse=peernhro if peernhry==1
replace uhourse=. if uhourse<0
replace uhourse=. if 99<uhourse
}
lab var uhours "Usual hours, main job"
notes uhours: Unedited
notes uhours: Available 1979-93 only
notes uhours: CPS: a-uslhrs

lab var uhourse "Usual hours, main job"
notes uhourse: Edited
notes uhourse: Available 94-on
notes uhourse: CPS: a-uslhrs, peernhro

	/* why usually work part-time */

gen byte why3579=.
gen byte why3594=.

#delimit ;
lab def why3579
1 "Slack work"
2 "Material shortage"
3 "Plant or machine repair"
4 "New job started during week"
5 "Job terminated during week"
6 "Could only find part-time work"
7 "Holiday"
8 "Labor dispute"
9 "Bad weather"
10 "Own illness"
11 "On vacation"
12 "Too busy with school, house"
13 "Did not want full-time work"
14 "Full-time work week is <35 hours"
15 "Other"
;
#delimit cr
lab val why3579 why3579




if 1994<=`year' & `year'<=2020 {
replace why3594=prptrea
replace why3594=. if prptrea<1
}

#delimit ;
lab def why3594
1 "Slack work, FT"
2 "Seasonal, FT"
3 "Job started or end last week, FT"
4 "On vacation, FT"
5 "Own illness, FT"
6 "Holiday, FT"
7 "Child-care problems, FT"
8 "Other family obligations, FT"
9 "Labor dispute, FT"
10 "Bad weather, FT"
11 "School/training, FT"
12 "Civic/military, FT"
13 "Other, FT"
14 "Slack work, PT"
15 "Could only find PT work, PT"
16 "Seasonal, PT"
17 "Child-care problems, PT"
18 "Other family obligations, PT"
19 "Own illness, PT"
20 "School/training, PT"
21 "Soc. Sec. earnings limitation, PT"
22 "Workweek <35 hours, PT"
23 "Other, PT"
;
#delimit cr
lab val why3594 why3594


lab var why3579 "Why usually <35 hours"
notes why3579: Available 1979-93 only
notes why3579: See also reason79
notes why3579: CPS: a-ftreas

lab var why3594 "Why usually <35 hours"
notes why3594: Available 1994-on
notes why3594: FT, PT refer to usual work schedule
notes why3594: CPS: prptrea

	/* part-time for economic reasons */

gen byte ptecon=.

/*	
if 1979<=`year' & `year'<=1988 {
replace ptecon=0 if ftpt79==1 | ftpt79==2 | ftpt79==4 /* employed only */
replace ptecon=1 if ftpt79==2
/* in NBER, "ptstat" variable appears to be inconsistent with ftpt79 */
}
if 1989<=`year' & `year'<=1993 {
replace ptecon=0 if 2<=ftpt89 & ftpt89<=5  /* employed only */
replace ptecon=1 if ftpt89==3 | ftpt89==5
}
*/

if `year'==1991 {
replace ptecon=0 if 2<=adwkstat & adwkstat<=5 /* employed only */
replace ptecon=1 if adwkstat==3 | adwkstat==5
}
if 1994<=`year' & `year'<=2020 {
replace ptecon=0 if 2<=prwkstat & prwkstat<=10  /* employed only */
replace ptecon=1 if prwkstat==3 | prwkstat==6
}
lab var ptecon "PT, economic reasons"
notes ptecon: CPS: derived from a-wkstat, prwkstat

	/* unemployed part-timers */

gen byte unempt=.

/*
if 1979<=`year' & `year'<=1988 {
replace unempt=0 if ftpt79==3 | ftpt79==5 /* unemployed only */
replace unempt=1 if ftpt79==5
}
if 1989<=`year' & `year'<=1993 {
replace unempt=0 if ftpt89==6 | ftpt89==7  /* unemployed only */
replace unempt=1 if ftpt89==7
}
*/
if `year'==1991 {
replace unempt=0 if 6<=adwkstat & adwkstat<=7 /* unemployed only */
replace unempt=1 if adwkstat==7
}
if 1994<=`year' & `year'<=2020 {
replace unempt=0 if prwkstat==11 | prwkstat==12  /* unemployed only */
replace unempt=1 if prwkstat==12
}
lab var unempt "Unemployed, PT"
notes unempt: CPS: derived from a-wkstat, prwkstat

/* "hours vary" */
if 1979<=`year' & `year'<=1993 {
gen byte prhrusl=.
gen byte pehrusl1=.
gen byte hrsvary=.
gen byte pehrusl2=.
gen byte pehruslt=.
gen byte peernhro=.
}
if 1994<=`year' & `year'<=2020 {
gen byte hrsvary=0 if pehrusl1~=-1 & pehrusl1~=0
replace hrsvary=1 if pehrusl1==-4
replace prhrusl=. if prhrusl==-1
}

lab var prhrusl "Usual hours, Basic CPS"
capture lab drop prhrusl
#delimit ;
lab def prhrusl
1 "0-20"
2 "21-34"
3 "35-39"
4 "40"
5 "41-49"
6 "50 or more hrs"
7 "Varies, FT"
8 "Varies, PT"
;
#delimit cr
lab val prhrusl prhrusl
notes prhrusl: Available 1994- only
notes prhrusl: CPS: prhrusl

lab var pehrusl1 "Usual hours, main (BLS)"
notes pehrusl1: Keeps "hours vary"=-4
notes pehrusl1: Extracted 1994- only; prior to 1994, see uhourse
notes pehrusl1: Basic CPS: hours per week USUALLY work at main job?
notes pehrusl1: CPS: pehrusl1

lab var hrsvary "Hours vary, main job"
notes hrsvary: Available 1994- only
notes hrsvary: CPS: pehrusl1==-4

lab var pehrusl2 "Usual hours, 2nd (BLS)"
notes pehrusl2: Keeps "hours vary"=-4
notes pehrusl2: Extracted 1994- only; prior to 1994, see uhourse
notes pehrusl2: Basic CPS: hours per week USUALLY work at other job(s)?
notes pehrusl2: CPS: pehrusl2

lab var pehruslt "Usual hours, all (BLS)"
notes pehruslt: Keeps "hours vary"=-4
notes pehruslt: CPS: pehruslt

lab var peernhro "Usual hours, ORG (BLS)"
notes peernhro: ORG: hours usually work per week at this rate?
notes peernhro: CPS: peernhro

/* impute hours for "hours vary" respondents 1994- */

if 1979<=`year' & `year'<=1993 {
gen byte imphrs=.
/* to simplify calculations later, set hours imputed to zero (rather
than missing) here */
gen byte hrsimptd=0
/* to simplify calculations later, set uhoursi (usual weekly hours
including imputation) equal to uhourse for years before the hours
vary response was permitted */
gen byte uhoursi=uhourse
}
if 1994<=`year' & `year'<=2020 {
	/* fit separate regressions: FT, PT; men and women */
tempvar agesq white black hisp lths hs col adv
gen `agesq'=age*age
gen byte `white'=wbho==1
gen byte `black'=wbho==2
gen byte `hisp'=wbho==3
gen byte `lths'=educ==1
gen byte `hs'=educ==2
gen byte `col'=educ==4
gen byte `adv'=educ==5
		/* FT, women */
reg pehrusl1 age `agesq' `white' `black' `hisp' /*
*/ `lths' `hs' `col' `adv' married forborn citizen /*
*/ /* union pubsector manuf servs manager */ /*
*/ if empl==1 & selfemp==0 & hrsvary==0 & /*
*/ (3<=prhrusl & prhrusl<=6) & female==1
predict imphr1 if female==1 & prhrusl==7 /* varies, FT */
		/* FT, men */
reg pehrusl1 age `agesq' `white' `black' `hisp' /*
*/ `lths' `hs' `col' `adv' married forborn citizen /*
*/ /* union pubsector manuf servs manager */ /*
*/ if empl==1 & selfemp==0 & hrsvary==0 & /*
*/ (3<=prhrusl & prhrusl<=6) & female==0
predict imphr2 if female==0 & prhrusl==7 /* varies, FT */
		/* PT, women */
reg pehrusl1 age `agesq' `white' `black' `hisp' /*
*/ `lths' `hs' `col' `adv' married forborn citizen /*
*/ /* union pubsector manuf servs manager */ /*
*/ if empl==1 & selfemp==0 & hrsvary==0 & /*
*/ (1<=prhrusl & prhrusl<=2) & female==1
predict imphr3 if female==1 & prhrusl==8 /* varies, PT */
		/* PT, men */
reg pehrusl1 age `agesq' `white' `black' `hisp' /*
*/ `lths' `hs' `col' `adv' married forborn citizen /*
*/ /* union pubsector manuf servs manager */ /*
*/ if empl==1 & selfemp==0 & hrsvary==0 & /*
*/ (1<=prhrusl & prhrusl<=2) & female==0
predict imphr4 if female==0 & prhrusl==8 /* varies, PT */

gen imphrs=imphr1 if female==1 & prhrusl==7
replace imphrs=imphr2 if female==0 & prhrusl==7
replace imphrs=imphr3 if female==1 & prhrusl==8
replace imphrs=imphr4 if female==0 & prhrusl==8
replace imphrs=. if imphrs<=0
replace imphrs=round(imphrs,1) /* round for consistency with hours variables */

gen hrsimptd=0 if lfstat==1
replace hrsimptd=1 if lfstat==1 & hrsvary==1 & imphrs~=.

/* create usual hours variable including imputations for hours vary */
	/* if hours don't vary, use usual hours at main job */
gen uhoursi=pehrusl1 if hrsvary==0
	/* if hours vary, regression-estimated use imputed hours */
replace uhoursi=imphrs if hrsvary==1 & hrsimptd==1 & imphrs~=.
	/* but if hourly and hours vary and respondent answers "usual hours
	   worked at this rate" (peernhro) use this as estimate
	   for usual hours instead of regression-based imputation */
replace uhoursi=peernhro if peernper==1 & hrsvary==1 & /*
*/ (1<=peernhro & peernhro<=99)
replace uhoursi=round(uhoursi,1)
}

lab var imphrs "Hours, main job (imputed)"
notes imphrs: Assigned to respondents "hours vary" using regression
notes imphrs: Regression excludes industry, occupation, union variables
notes imphrs: Ind, occ, union vars significantly reduces imputation match rate

lab var hrsimptd "Hours imputed"
notes hrsimptd: See imphrs

lab var uhoursi "Hours, w/ imputation"
notes uhoursi: See imphrs
notes uhoursi: CPS pehrusl1 variable, with imputed hours where pehrusl1==-4

/* BLS imputations for hours */

gen byte blsimpt=.

if `year'==1991 {replace blsimpt=1 if apuslhrs==4}
if `year'~=1991 {
	replace blsimpt=0 if pxhrusl1==0
	replace blsimpt=1 if 0<pxhrusl1 & pxhrusl1~=.
}
lab var blsimpt "BLS allocated weekly hours"
notes blsimpt: Indicates BLS has allocated usual weekly hours at main job
notes blsimpt: CPS: derived from a%uslhrs, pxhrusl1

/* 
Copyright 2020 CEPR and John Schmitt

This file is part of the cepr_org_master.do program. This file and all
programs referenced in it are free software. You can redistribute the
program or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA.
*/
